﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ExpreRec.DataAccess;

namespace ExpreRec.Logic.Util
{
    public class Variable
    {
        private static VariableDAL dal = new VariableDAL();

        private static int toInt(string v)
        {
            if (!string.IsNullOrWhiteSpace(v))
            {
                int res;
                if (int.TryParse(v, out res))
                    return res;
            }
            return -1;
        }

        private static double toDouble(string v)
        {
            if (!string.IsNullOrWhiteSpace(v))
            {
                double res;
                if (double.TryParse(v, out res))
                    return res;
            }
            return -1;
        }

        private static string def(string v, string def)
        {
            if (!string.IsNullOrWhiteSpace(v))
                return v;
            else return def;
        }

        public static string ClassificationMethod
        {
            get
            {
                return def(dal.GetValue("ClassificationMethod"), "KNN");
            }
        }

        public static int KNNParamK
        {
            get
            {
                return toInt(dal.GetValue("KNNParamK"));
            }
        }
        private static int KNNParamDistVoteFlagInt
        {
            get
            {
                return toInt(dal.GetValue("KNNParamDistVoteFlag"));
            }
        }
        public static bool KNNParamDistVoteFlag
        {
            get
            {
                return KNNParamDistVoteFlagInt == 0 ? false : true;
            }
        }
        public static double KNNParamDistR
        {
            get
            {
                return toDouble(dal.GetValue("KNNParamDistR"));
            }
        }

        public static bool KNNParamSet
        {
            get
            {
                return (KNNParamK != -1 && KNNParamDistVoteFlagInt != -1 && KNNParamDistR != -1);
            }
        }
    }
}
